## This script: Local newspaper consumption and center party support using GLES 2009
## ORIGINAL DATA IS AVAILABLE FROM GESIS: https://search.gesis.org/research_data/ZA5300 
## GLES (2019). Pre-election Cross Section (GLES 2009). GESIS Data Archive, Cologne. ZA5300 Data file Version 5.0.2, https://doi.org/10.4232/1.13228.


rm(list = ls())
library(tidyverse)
library(lfe)
library(stargazer)

## Load Data
# gles_full <- haven::read_dta('data/GLES_2009_ZA5300_de_v5-0-2.dta')
gles <- haven::read_dta("data_original_DO_NOT_UPLOAD/GLES_2009_ZA5300_de_v5-0-2.dta")

## Variables that relate to national newspaper readership 
tz_vars <- c('q101a', 'q101b' , 'q101c',
             'q101d',  'q101e', 'q101f', "q101g")

party_id <- c('q139a', "q11b")
center_party <- c('CDU/CSU', 'SPD')

## Clean up 
gles <- gles %>% 
  dplyr::select(one_of(c(tz_vars, party_id, "land", "vw_lfdn" ))) %>%
  mutate_at(tz_vars, ~ ifelse(. == 1, 1, 0)) %>% 
  rename('read_bild' = 1,
         'read_faz' = 2,
         'read_welt' = 3,
         'read_sz' = 4,
         'read_fr' = 5,
         'read_taz' = 6,
         "read_local" = 7, 
         'party_id' = 8,
         'vote_intent' = 9) %>%
  mutate(party_id = recode(as.character(party_id),
                           `808` = 'None',
                           `801` = 'Other',
                           `997` = 'Other',
                           `998` = 'None',
                           `2` = 'CDU/CSU',
                           `1` = 'CDU/CSU',
                           `3` = 'CDU/CSU',
                           `4` = 'SPD',
                           `5` = 'FDP',
                           `6` = 'Greens',
                           `7` = 'Linke')) %>% 
  mutate(vote_intent = recode(as.character(vote_intent),
                              `999` = 'None',
                              `801` = 'Other',
                              `997` = 'Other',
                              `998` = 'None',
                              # `1000` = NA,
                              `1` = 'CDU/CSU',
                              # `3` = 'CDU/CSU',
                              `4` = 'SPD',
                              `5` = 'FDP',
                              `6` = 'Greens',
                              `7` = 'Linke') ) %>% 
  mutate(
    center_vote = if_else(vote_intent %in% center_party,1,0 ),
    center_id = if_else(party_id %in% center_party,1,0 )
  ) %>% 
  mutate(
    read_none = read_local + read_bild + read_faz + read_welt + read_sz + read_fr + read_taz 
  ) %>% 
  mutate(
    read_none = if_else(read_none > 0, 0, 1)
  )
    
## Set Missings NA  
gles$party_id[gles$party_id == '999'] <- NA
gles$party_id[gles$vote_intent == '999'] <- NA
gles$party_id[gles$vote_intent == '1000'] <- NA

gles$party_id[gles$party_id == 'None'] <- NA
gles$party_id[gles$party_id == 'Other'] <- NA

gles$party_id[gles$vote_intent == 'None'] <- NA
gles$party_id[gles$vote_intent == 'Other'] <- NA


## Run Models

m1 <- felm(center_vote ~ read_local + read_bild  
           | land | 0 | vw_lfdn, data = gles)

m2 <- felm(center_id ~ read_local + read_bild  
           | land | 0 | vw_lfdn, data = gles)


stargazer(m1, m2,
          keep.stat = c('n', 'rsq'),
          covariate.labels = c('Reads Local',
                               'Reads Bild',
                               'Reads None'),
          dep.var.labels = c('Center Party Vote',
                              'Center Party Identification'),
          type = 'text',
          add.lines = list(c('Fixed Effects', 'State', 'State'))
          )
          






